// 1. 枚举定义方式，用C语言方式定义枚举
enum IpAddKind {
    v4,
    v6,
}
struct IpAddr {
    kind: IpAddKind,
    address: String,
}
// 2. Rust语言方式定义枚举
enum IpAddr2 {
    v4(String),
    v6(String),
}

// 3. 可以是不同类型
enum IpAddr3 {
    v4(u8, u8, u8, u8),
    v6(String),
}
// 4. 经典用法
enum Message {
    // 等同于struct QuitMessage; //类单元结构体
    Quit,
    /***
    // 等同于
    struct MoveMessage{
        x: i32,
        y:i32,
    };
     */
    Move { x: i32, y: i32 },
    // 等同于struct WriteMessage(String);
    Write(String),
    // 等同于struct ChangeColor(i32, i32, i32);
    ChangeColor(i32, i32, i32),
}
// 5. 枚举类型的方法以及match, 引用第4点的枚举
impl Message {
    fn print(&self) {
        match self {
            Message::Quit => println!("Quit"),
            Message::Move { x, y } => println!("Move x: {},  Move y: {}", x, y),
            Message::ChangeColor(a, b, c) => println!("Change color: {} {} {}", a, b, c),
            _ => println!("Write"),
            Message::Write(s) => println!("Write: {}", s),
        }
    }
}
fn main() {
    let quit = Message::Quit;
    quit.print();
    let mo = Message::Move { x: 10, y: 20 };
    mo.print();
    let write = Message::Write("Hello, world!".to_string());
    write.print();
    let change_color = Message::ChangeColor(0, 255, 255);
    change_color.print();

    let i1 = IpAddr {
        kind: IpAddKind::v4,
        address: String::from("127.0.0.1"),
    };
    let i2 = IpAddr {
        kind: IpAddKind::v6,
        address: String::from("::1"),
    };

    let i1 = IpAddr2::v4(String::from("127.0.0.1"));
    let i2 = IpAddr2::v6(String::from("::1"));

    let i1 = IpAddr3::v4(127, 0, 0, 1);
    let i2 = IpAddr3::v6(String::from("::1"));
    println!("Hello, world!");
}
